namespace YMJake.Flowable.ExternalWorker.Client.Core.Rest
{
    /// <summary>
    /// Exception thrown when a Flowable REST API call fails
    /// </summary>
    public class FlowableRestException : Exception
    {
        public int StatusCode { get; }
        
        public FlowableRestException(int statusCode, string? content = null) 
            : base(CreateMessage(statusCode, content))
        {
            StatusCode = statusCode;
        }
        
        private static string CreateMessage(int statusCode, string? content)
        {
            if (!string.IsNullOrEmpty(content))
            {
                return $"Failed to call Flowable with status code {statusCode} and content '{content}'";
            }
            return $"Failed to call Flowable with status code {statusCode}";
        }
    }
}